﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Reflection;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CrazyTalk.Common;
using CrazyTalk.Web.UI;
using CrazyTalk.Common.StringExtension;

namespace CrazyTalk.Web.User.Message
{
    public partial class List : BasePage
    {
        protected new void Page_Load(object sender, EventArgs e)
        {
            try
            {
                String methodName = Request["method"];

                Type type = GetType();
                MethodInfo method = type.GetMethod(methodName);
                if (method == null) throw new Exception("method is null");
                method.Invoke(this, null);
            }
            catch (Exception ex)
            {
                //Response.Redirect("../Login.html");
                Response.Write("error" + ex.Message);
            }
        }
        public void GetList()
        {
            int pageIndex = FormToInt("page");
            int pageSize = FormToInt("rows");
            List<string> queryFields = new List<string>();
            List<object> queryValues = new List<object>();
            //queryFields.Add("a.ReceiverId");
            //queryValues.Add(UserInfo.ID);

            string messageType = Form("MessageType");
            string messagePriority = Form("MessagePriority");
            string readedSearch = Form("ReadedSearch");
            if (!string.IsNullOrEmpty(messageType))
            {
                queryFields.Add("b.TypeId");
                queryValues.Add(messageType);
            }
            if (!string.IsNullOrEmpty(messagePriority))
            {
                queryFields.Add("b.PriorityId");
                queryValues.Add(messagePriority);
            }
            if (!string.IsNullOrEmpty(readedSearch))
            {
                queryFields.Add("a.Readed");
                queryValues.Add(readedSearch);
            }

            //Hashtable list = Common.Service.ServiceManager.Instance.BaseMessageReceiveService.GetList(queryFields, queryValues, pageIndex, pageSize);
            //String json = JSON.Encode(list);
            //Response.Write(json);
        }
        /// <summary>
        /// 显示用户消息内容
        /// </summary>
        public void GetDetail()
        {
            int keyId = QueryToInt("id");
            //DataTable dtb = Common.Service.ServiceManager.Instance.BaseMessageReceiveService.GetMessage(keyId, UserInfo.ID);
            //String json = JSON.Encode(dtb);
           //Response.Write(json);
        }
        /// <summary>
        /// 删除用户消息逻辑
        /// </summary>
        public void Delete()
        {
            int keyId = QueryToInt("id");
            //只能删除发给自己的信息
            //Response.Write(Common.Service.ServiceManager.Instance.BaseMessageReceiveService.Delete(keyId, UserInfo.ID)
            //                   ? "已成功删除信息"
            //                   : "删除信息失败");
        }

        /// <summary>
        /// 批量删除用户消息逻辑
        /// </summary>
        public void DeleteMulti()
        {
            string keyId = Query("idl");
            if (string.IsNullOrEmpty(keyId))
            {
                Response.Write("传入参数有误");
            }
            else
            {
                List<int> idList = keyId.ToList<int>(',');
                if (idList == null || idList.Count == 0)
                {
                    Response.Write("传入参数有误");
                    return;
                }
                //Response.Write(
                //    Common.Service.ServiceManager.Instance.BaseMessageReceiveService.Delete(idList,
                //                                                                            UserInfo.ID) > 0
                //        ? "已成功删除信息"
                //        : "删除信息失败");
            }
        }
    }
}